package com.sk.sourcecircle.adapter;

import android.graphics.Color;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sk.sourcecircle.R;
import com.sk.sourcecircle.entity.MoreSourceListBean;
import com.sk.sourcecircle.utils.MyUtils;

import java.util.List;

/**
 * Created by sk on 2018/1/1.
 */

public class MoreRoundSourceAdapter extends BaseMultiItemQuickAdapter<MoreSourceListBean.DataBean, BaseViewHolder> {


    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public MoreRoundSourceAdapter(List<MoreSourceListBean.DataBean> data) {
        super(data);
        addItemType(0, R.layout.item_round_source);
        addItemType(1, R.layout.item_recommend_event);
    }

    @Override
    protected void convert(BaseViewHolder helper, MoreSourceListBean.DataBean item) {
        boolean isNotEnd = false;
        String createTime = item.getCreate_time();
        helper.setText(R.id.event_name, item.getName());

        if(Double.parseDouble(item.getMin_price())>0){

            helper.setText(R.id.tv_price,"￥"+item.getMin_price()).setTextColor(R.id.tv_price, Color.parseColor("#ff5050"));

        }else {
            helper.setText(R.id.tv_price,"免费").setTextColor(R.id.tv_price, Color.parseColor("#219021"));

        }


        String applyEndTime = MyUtils.timedate(String.valueOf(item.getApply_end_time()));

        isNotEnd = MyUtils.compareTwoTime("", applyEndTime);

        if (isNotEnd) {
            String leaveTime = MyUtils.getTimeDifference("", applyEndTime);
            helper.setText(R.id.tv_time, MyUtils.getTimeFormatText(createTime) + "   距离结束还有" + leaveTime);
        } else {
            helper.setText(R.id.tv_time, MyUtils.getTimeFormatText(createTime) + "   报名已截止");
        }

        helper.setText(R.id.event_name, item.getName())
                .setText(R.id.tv_name, item.getCommunity_name())
                .setText(R.id.tv_location, item.getAddress());
        Glide.with(mContext).load(item.getHead_url()).into((ImageView) helper.getView(R.id.item_bg));
        switch (item.getItemType()) {
            case 0:
                helper.setText(R.id.order_num, item.getOrders() + "人报名");
                break;
            case 1:
                break;
        }
    }
}
